package ModelLayer;
import java.util.ArrayList;


public class DiscountList
{
    
    private ArrayList<Discount> discounts;
    private static DiscountList instance;

    
    public DiscountList()
    {
        discounts = new ArrayList<Discount>();
    }

    public static DiscountList getInstance()
    {
        if(instance == null)
        {
            instance = new DiscountList();
        }
        return instance;
    }
    
    public void addDiscount (Discount newDiscount)
    {
       discounts.add(newDiscount);
    }
    
     public void deleteDiscount(long discountId)
    {
        Discount discount = findDiscount(discountId);
        discounts.remove(discount);
    }
    
    public Discount findDiscount(long discountId)
    {
        boolean discountFound = false;
        int index = 0;
        while(index < discounts.size() && !discountFound)
        {
            Discount s = discounts.get(index);
            if(s.getDiscountId() == discountId)
            {
                discountFound = true; 
            }
            else
            {
                index++;
            }
            
        }
        
        if(discountFound)
        {
            return discounts.get(index);
        }
        else
        {
            
            return null;
        }
}
}